import {
  SEARCH_FOCUS,
  SEARCH_BLUR,
  CHANGE_LIST,
  ON_MOUSE_ENTER,
  ON_MOUSE_LEAVE,
  ON_CHANGE_PAGE
} from "./types";
import { fromJS } from "immutable";
const defaultState = fromJS({
  focused: false,
  moserIn: false,
  list: [],
  page: 1,
  totalPage: 1
});

export default (state = defaultState, action) => {
  switch (action.type) {
    case SEARCH_FOCUS:
      return state.set("focused", true);
    case SEARCH_BLUR:
      return state.set("focused", false);
    case ON_MOUSE_ENTER:
      return state.set("moserIn", true);
    case ON_MOUSE_LEAVE:
      return state.set("moserIn", false);
    case ON_CHANGE_PAGE:
      return state.set("page", action.page);
    case CHANGE_LIST:
      return state.merge({
        list: action.data,
        totalPage: action.totalPage
      });
    default:
      return state;
  }
};
